<?php
class info_product extends Model{
	public static function getTableName(){
		return 'info_product';
	}

	public function set($object){
		$this->product_name_chinese= !isset($object->product_name_chinese) ? '' : trim($object->product_name_chinese);
		$this->product_name_english= !isset($object->product_name_english) ? '' : trim($object->product_name_english);
		$this->brand= !isset($object->brand) ? '' : trim($object->brand);
		$this->industry= !isset($object->industry) ? '0' : $object->industry;
		$this->description= !isset($object->description) ? '' : $object->description;
		$this->url= !isset($object->url) ? '' : trim($object->url);
		$this->status= !isset($object->status) ? '0' : $object->status;
		$this->created_by= !isset($object->created_by) ? '' : $object->created_by;
		$this->created_at= !isset($object->created_at) ? '' : $object->created_at;
		$this->modified_by= !isset($object->modified_by) ? '' : $object->modified_by;
		$this->modified_at= !isset($object->modified_at) ? '' : $object->modified_at;
		$this->episode_id= !isset($object->episode_id) ? '' : $object->episode_id;
        $this->publish_datetime = !isset($object->publish_datetime) ? '' : $object->publish_datetime;
	    $this->expire_datetime  = !isset($object->expire_datetime) ? '' :  $object->expire_datetime;

        if( is_array($this->publish_datetime) || is_array($this->expire_datetime) )
        {    
            $this->publish_datetime = empty($object->publish_datetime) ? '' : implode(' ',$object->publish_datetime );
		    $this->expire_datetime  = empty($object->expire_datetime) ? '' :  implode(' ',$object->expire_datetime );
       
        }
        /*
        else
        {
            $this->publish_datetime = !isset($object->publish_datetime) ? '' : $object->publish_datetime;
	        $this->expire_datetime  = !isset($object->expire_datetime) ? '' :  $object->expire_datetime;
        }
         */
    
	}

	/*
	 * by donald
	 */
	public function add_change_log()
	{
		$field['type'] = $this->getTableName();
		$field['keys'] = array('id' => $this->id);
		$field['is_active'] = 1;
		$field['programme_id'] = 0;
		$field['episode_id'] = $this->episode_id;
		$field['is_publish'] = 0;

		change_log::updateOne($field);
	}

	/*
	 * by donald
	 */
	public function delete_change_log()
	{
		$type = $this->getTableName();
		$keys = array('id' => $this->id);
		$is_publish = 0;

		change_log::delTypeAndKeysLog($type, $keys, $is_publish);
	}
}
?>
